package 快排;

/**
 * @author wtcode
 * @date 2021/3/23 - 14:59
 */
public class QuickSort2 {

    public static void sort(int[] a) {
        if (a.length > 0) {
            sort(a, 0, a.length - 1);
        }
    }

    private static void sort(int[] a, int left, int right) {
        int i = left;
        int j = right;
        int pivot = a[left];

        while(i < j){
            while(i < j && a[j] > pivot){
                j--;
            }
            while (i < j && a[i] < pivot){
                i++;
            }
            if(i < j){
                int temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
        pivot = a[i];
        a[i] = a[left];
        a[left] = pivot;

    }


}
